package com.example.exam.ZhangFengHua;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.exam.R;

import java.util.List;

public class Fruits_Adapter extends ArrayAdapter<Fruits_list> {
    private int resourceId;
    public Fruits_Adapter(@NonNull Context context, int resource, List<Fruits_list> object) {
        super(context, resource,object);
        resourceId=resource;
    }
    public View getView(int position , View convertView , ViewGroup parent){
        Fruits_list fruits_list=getItem(position);//获取当前的实例化
        View view= LayoutInflater.from(getContext()).inflate(resourceId,parent,false);
        ImageView fruitImage=(ImageView)view.findViewById(R.id.de_tp);
        TextView fruitname=(TextView)view.findViewById(R.id.tv_text);
        fruitImage.setImageResource(fruits_list.getImageid());
        fruitname.setText(fruits_list.getName());
        return  view;
    }
}
